package com.etoak.controller;


import com.etoak.common.core.vo.PageVO;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.service.DishesService;
import com.etoak.vo.DishesVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 前端控制器
 *
 * @author etoak
 * @since 2025-07-28
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {

    @Autowired
    DishesService dishesService;

    /**
     * 添加菜品
     */
    @PostMapping
    public ResultVO<Object> add(@Validated @RequestBody Dishes dishes) {
        dishesService.add(dishes);
        return ResultVO.success();
    }

    @GetMapping("/list")
    public ResultVO<PageVO<DishesVO>> getList(@RequestParam(defaultValue = "1", required = false) int pageNum,
                                              @RequestParam(defaultValue = "10", required = false) int pageSize,
                                              Dishes dishes) {
        PageVO<DishesVO> pageVO = dishesService.getList(pageNum, pageSize, dishes);
        return ResultVO.success(pageVO);
    }

    @PutMapping("/{id}")
    public ResultVO<Object> updateDishes(@PathVariable int id, @RequestBody Dishes dishes) {
        dishesService.updateDishes(id, dishes);
        return ResultVO.success();
    }

    @DeleteMapping("/{id}")
    public ResultVO<Object> deleteDishes(@PathVariable int id) {
        dishesService.deleteDishes(id);
        return ResultVO.success();
    }

    @GetMapping("/{ids}")
    public ResultVO<List<DishesVO>> getByIds(@PathVariable List<Integer> ids) {
        List<DishesVO> dishesVOList = dishesService.getByIds(ids);
        return ResultVO.success(dishesVOList);
    }
}

